# -*- coding: utf-8 -*-
#!/usr/bin/env python

import pylab, atpy, param_finder_modules
import numpy

tbl_overall = atpy.Table('/home/jeffrey/PHD/ruawahia/data/vizier_votable.vot')
#tbl_overall.sort('LEID')
LEIDfile = open('/home/jeffrey/PHD/ruawahia/data/group_of_similar_star_LEID_090611_small','r')

#LEID=tbl_overall.data['LEID'][1]
#print type(LEID)
#print LEID
#tbl = tbl_overall.where((tbl_overall.LEID == LEID))
#print tbl[0]
#spFile=tbl.data['spFile'][0]
#print spFile

def spectrum_loader(filename,cont_shift):
	spectrum = open(filename,'r')
	wavel=[]; intensity=[];
	for line in spectrum:
	    double=line.split()
	    wavel.append(float(double[0]))
	    intensity.append(float(double[2])+cont_shift)
	return wavel,intensity

def moog_spectrum_loader(filename):
	spectrum = open(filename,'r')
	wavel=[]; intensity=[];
	for line in spectrum:
	    double=line.split()
	    wavel.append(float(double[0]))
	    intensity.append(float(double[1]))
	return wavel,intensity

pylab.figure(1)
#LEID=[], cont_shirt=[]
i=0
for line in LEIDfile:
	i=i+1
	doub = line.split()
	LEID=numpy.int32(doub[0])
	tbl = tbl_overall.where((tbl_overall.LEID == LEID))
	print tbl[0]
	spFile=tbl.data['spFile'][0]
	nS=tbl.data['nS'][0]
	[wave, intensity, specnum]=param_finder_modules.load_vanloon_spectrum(nS,spFile)
	for index, object in enumerate(intensity):
	    intensity[index] = object+float(doub[1])
	#[wave,intensity]=spectrum_loader('/home/jeffrey/PHD/isooctane/data/jaccodata/'+spFile,0.02)
	#print doub[2]
	pylab.plot(wave, intensity)
	if i==4:
		break
pylab.xlim([4540,4580])
pylab.ylim([0.5,1.05])
pylab.show()
